<script setup>
import { useBanner } from './composables/useBanner'
import { useCategory } from './composables/useCategory'
import { imageBaseURL } from '@/utils/request'

const { categoryData } = useCategory()
const { bannerList } = useBanner()
</script>

<template>
  <div class="top-category">
    <div class="container m-top-20">
      <!-- 面包屑 -->
      <!-- <div class="bread-container">
        <el-breadcrumb separator=">">
          <el-breadcrumb-item :to="{ path: '/' }">首页11</el-breadcrumb-item>
          <el-breadcrumb-item>{{ categoryData.name }}</el-breadcrumb-item>
        </el-breadcrumb>
      </div> -->
      <!-- 轮播图 -->
      <div class="home-banner">
        <el-carousel height="500px">
          <el-carousel-item v-for="item in bannerList" :key="item.id">
            <img :src="item.imgUrl" alt="" />
          </el-carousel-item>
        </el-carousel>
      </div>
      <!-- <div class="sub-list">
        <h3>全部分类</h3>
        <ul>
          <li v-for="i in categoryData.children" :key="i.id">
            <RouterLink :to="`/category/sub/${i.id}`">
              <img :src="i.picture" />
              <p>{{ i.name }}</p>
            </RouterLink>
          </li>
        </ul>
      </div> -->
      <div class="ref-goods">
        <div class="head">
          <h3>-- 商品列表 --</h3>
        </div>
        <div class="body">
            <ul class="goods-list">
              <li v-for="good in categoryData" :key="good.id">
                <RouterLink :to="`/detail/${good.id}`">
                  <img :src="imageBaseURL + good.picture" alt="" />
                  <p class="name">{{ good.name }}</p>
                  <p class="desc">{{ good.description }}</p>
                  <p class="price">&yen;{{ good.price }}</p>
                </RouterLink>
              </li>
            </ul>
          </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.top-category {
  // h3 {
  //   font-size: 28px;
  //   color: #666;
  //   font-weight: normal;
  //   text-align: center;
  //   line-height: 100px;
  // }
  h3 {
      flex: 1;
      font-size: 32px;
      font-weight: normal;
      height: 35px;
      line-height: 35px;
      text-align: center;;
      margin-bottom: 30px;

}
  .sub-list {
    margin-top: 20px;
    background-color: #fff;

    ul {
      display: flex;
      padding: 0 32px;
      flex-wrap: wrap;

      li {
        width: 168px;
        height: 160px;

        a {
          text-align: center;
          display: block;
          font-size: 16px;

          img {
            width: 100px;
            height: 100px;
          }

          p {
            line-height: 40px;
          }

          &:hover {
            color: $xtxColor;
          }
        }
      }
    }
  }
  .ref-goods {
    background-color: #fff;
    margin-top: 20px;
    position: relative;

    .head {
      .xtx-more {
        position: absolute;
        top: 20px;
        right: 20px;
      }

      .tag {
        text-align: center;
        color: #999;
        font-size: 20px;
        position: relative;
        top: -20px;
      }
    }
    .body {
      .goods-list {
        width: 100%;
        max-width: 1200px;
        margin: 0 auto;
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 15px;
        padding: 0 15px;

        li {
          background: #ffffff;
          border: 1px solid #e7e7e7;
          border-radius: 5px;
          padding: 10px;
          transition: all 0.3s;

          &:hover {
            transform: translate3d(0, -3px, 0);
            box-shadow: 0 3px 8px rgb(0 0 0 / 10%);
          }

          img {
            width: 100%;
            height: 160px;
            object-fit: cover;
            border-radius: 4px;
          }

          p {
            font-size: 14px;
            padding: 6px 0;
            text-align: left;
            overflow: hidden;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            white-space: normal;
          }

          .price {
            color: $priceColor;
            font-size: 22px;
            font-weight: bold;
            margin-top: 8px;
            position: relative;
            padding-left: 50px;

            &::before {
              content: '特卖价';
              position: absolute;
              left: 0;
              top: 50%;
              transform: translateY(-50%);
              display: inline-block;
              width: 45px;
              height: 18px;
              background-image: repeating-linear-gradient(90deg, #dc459f 0, #cc75d8 100%);
              color: #ffffff;
              font: 12px/18px "微软雅黑";
              text-align: center;
              border-radius: 9px;
            }
          }
        }
      }
    }
  }
  .bread-container {
    padding: 25px 0;
    :deep(.el-breadcrumb__item) {
      .el-breadcrumb__inner {
        font-size: 25px;
        &:hover {
          color: $xtxColor;
        }
      }
    }
  }
  .home-banner {
    width: 1240px;
    height: 500px;
    margin: 0 auto;

    img {
      width: 100%;
      height: 500px;
    }
  }
}
</style>
